<?php
namespace lightblog\engine;

use lightblog\engine\view;
// use lightblog\engine\model;

class controller {
    function __construct() {
        $this->module = \lightblog::$app->request->module;
        $this->controller = \lightblog::$app->request->controller;
        $this->action = \lightblog::$app->request->action;
        $this->view = new view($this->module, $this->controller, $this->action);
    }

    function render($data = array()) {
        return $this->view->display($data);
    }

    function renderFile($tpl = "", $data = array()) {
        return $this->view->displayFile($tpl, $data);
    }

    /* 错误处理
     *
     * @param string $msg 提示消息
     * @param string $goto 跳到哪里去
     */
    function error($msg) {
        $data = array(
            'msg' => $msg,
        );
        echo $this->renderFile('error', $data);
    }

    /* 成功后的跳转函数
     *
     * @param string $msg 提示消息
     * @param string $goto 跳到哪里去, 不写就跳到来的页面
     * @param integer $wait 跳转前等待的时间
     */
    function success($msg, $goto = "", $wait = 3) {
        $data = array(
            'msg' => $msg,
            'goto' => $goto,
            'wait' => $wait,
        );
        echo $this->renderFile('success', $data);
    }
}
